<template>
  <div class="lists">
    <el-table
      :data="goodsListData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      height="510"
    >
      <el-table-column prop="id" label="编号" sortable width="80">
      </el-table-column>
      <el-table-column prop="goodsname" label="商品名称" sortable width="160">
      </el-table-column>
      <el-table-column prop="price" label="商品价格" width="100"> </el-table-column>
      <el-table-column prop="market_price" label="市场价格" width="100"> </el-table-column>

      <el-table-column prop="address" label="图片" >
        <template slot-scope="scope">
          <img :src="baseURL + scope.row.img" />
        </template>
      </el-table-column>

      <el-table-column prop="isnew" label="是否新品" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isnew == 1">是</el-tag>
          <el-tag v-if="scope.row.isnew == 2" type="danger">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否热卖" width="100"> 
        <template slot-scope="scope">
          <el-tag v-if="scope.row.ishot == 1">是</el-tag>
          <el-tag v-if="scope.row.ishot == 2" type="danger">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1">启用</el-tag>
          <el-tag v-if="scope.row.status == 2" type="danger">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="editGoods(scope.row.id)">编辑</el-button>
          <el-button type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getGoodsList, } from "../../../request/api";
export default {
  data() {
    return {
      // 商品列表数据
      goodsListData: [],
    };
  },

  methods: {
    // 获取商品列表数据
    getGoodsListData() {
      getGoodsList().then(
        (res) => {
          if (res.data.code == 200) {
            this.goodsListData = res.data.list;
          }
        },
        (err) => err
      );
    },
    // 传给父组件
    editGoods(id){
      this.$emit("editGoods",id)
    }
  },
  mounted() {
    this.getGoodsListData();
  },
};
</script>

<style>
.cell img{
  width: 100px;
  height: 100px;
}
</style>